﻿using System.Data.Entity.ModelConfiguration;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    public class OrderExecutionMap : EntityTypeConfiguration<OrderExecution> {
        public OrderExecutionMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.pfm_order_executions");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(a => a.OrderExecutionId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // None

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // Order ... OrderExecution
            HasRequired<Order>(a => a.Order)
                .WithMany()
                .HasForeignKey(a => a.OrderId);

            /*
            HasRequired<ManagedProductPosition>(a => a.ManagedProductPosition)
                .WithMany()
                .HasForeignKey(a => a.ManagedProductPositionId);

            */
            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(a => a.OrderExecutionId)
                .IsRequired()
                .HasColumnName("moe_id");

            Property(a => a.OrderId)
                .IsRequired()
                .HasColumnName("moe_mpo_id");

            /*
            Property(a => a.ManagedProductPositionId)
                .IsRequired()
                .HasColumnName("moe_mpp_id");
                */
            
            Property(a => a.ExecutionDate)
                .IsRequired()
                .HasColumnName("moe_ts");

            Property(a => a.Quantity)
                .IsRequired()
                .HasColumnName("moe_amount");

            Property(a => a.PartialExecution)
               .IsRequired()
               .HasColumnName("moe_partial_fg");

            Property(a => a.Quote)
               .IsRequired()
               .HasPrecision(18, 6)
               .HasColumnName("moe_quote");

            Property(a => a.Fees)
               .IsRequired()
               .HasPrecision(18, 6)
               .HasColumnName("moe_fees");

            Ignore(a => a.NetAmount);

            Ignore(a => a.TotalAmount);
            
        }
    }
}
